# Contributor: Noel Kuntze <noel.kuntze@thermi.consulting>
# Maintainer: Noel Kuntze <noel.kuntze@thermi.consulting>
pkgname=libmdbx
pkgver=0.11.8
pkgrel=0
pkgdesc="fast, compact, powerful, embedded, transactional key-value database, with permissive license"
url="https://libmdbx.dqdkfa.ru/"
arch="all"
license="OLDAP-2.8"
makedepends="linux-headers cmake bash samurai"
subpackages="$pkgname-dbg $pkgname-dev $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/Thermi/libmdbx/archive/refs/tags/v$pkgver.tar.gz
	0001-mdbx-Remove-all-checks-for-amalgated-or-git-source-i.patch
	fix-example.patch
	"

build() {
	echo "$pkgver.0" > VERSION

	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	export CFLAGS="$CFLAGS -fPIC -Wno-int-to-pointer-cast"
	cmake -G Ninja -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DMDBX_ENABLE_TESTS=True \
		$CMAKE_CROSSOPTS
	cmake --build build
}

check() {
	TEST_DB=/tmp/mdbx-test.db TEST_LOG=/tmp/mdbx-test.log.gz \
		ninja -C build mdbx-test test-singleprocess build-test
	rm /tmp/mdbx-test.*
}

package() {
	DESTDIR="$pkgdir" cmake --build build --target install
}

sha512sums="
5751de7e288dc63f428a3cbeea5e9e355bfc96163d826b1a9d55c44b1b9b0e22c2dedba56d4ebca2d2edd7c85d7f6724526cf6183b2dd497e2cf7307548e0095  libmdbx-0.11.8.tar.gz
5e5fef4219279b10f0d4371fcbf3e2d4a7d958eb337f9de92aebb6a7d0d6644faa65eb804f46021678997a638ac601b03d9facbbf1164b45ae9075384d300df2  0001-mdbx-Remove-all-checks-for-amalgated-or-git-source-i.patch
baeb79efa7bb5d36af474f6dbefece9c597cf0b4d86cee96b9855da9cba4ee43aa46fab97c0c85c74ac76df9c4e3adc39666775ae14d79c394d07344569940ce  fix-example.patch
"
